package com.briup.myblog.web.controller;


import com.briup.myblog.aop.Logging;
import com.briup.myblog.bean.basic.BaseUser;
import com.briup.myblog.bean.basic.Comment;
import com.briup.myblog.bean.ext.CommentExt;
import com.briup.myblog.exception.CustomerException;
import com.briup.myblog.service.IBaseLogService;
import com.briup.myblog.service.IBaseUserService;
import com.briup.myblog.service.ICommentService;
import com.briup.myblog.utils.Result;
import com.briup.myblog.utils.ResultUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Api(tags = "评论模块")
@RestController
@RequestMapping("/auth/comment")
public class CommentController {
    @Autowired
    private ICommentService service;
    @Autowired
    private IBaseUserService baseUserService;
    @ApiOperation("审核评论")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "评论编号",required = true),
            @ApiImplicitParam(name = "status",value = "状态",required = true)
    })
    @Logging
    @PutMapping("/check")
    public Result checkComment(int id, int status){
            service.checkComment(id,status);
            return ResultUtil.success("审核成功");
    }
    @ApiOperation("分页查询所有评论信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keywords",value = "关键词",required = true),
            @ApiImplicitParam(name = "pageNum",value = "起始页",required = true),
            @ApiImplicitParam(name = "pageSize",value = "页长",required = true)
    })
    @Logging
    @GetMapping("/pageQuery")
    public Result pageQuery(int pageNum,int pageSize,String keywords){
        PageHelper.startPage(pageNum,pageSize);
        PageInfo<CommentExt>pageInfo = service.pageQuery(pageNum,pageSize,keywords);
        return ResultUtil.success(pageInfo);
    }
    @ApiOperation("根据id删除评论")
    @ApiImplicitParam(name = "id",value = "评论编号",required = true)
    @Logging
    @DeleteMapping("/deleteById")
    public Result deleteById(int id){
            service.deleteById(id);
            return ResultUtil.success("删除成功");
    }
    @ApiOperation("根据id批量删除评论")
    @Logging
    @DeleteMapping("/batchDelete")
    public Result batchDelete(Integer[] ids){
            service.batchDelete(ids);
            return ResultUtil.success("删除成功");
    }
}
